﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Unity.Errors.root;

namespace Unity.Errors.types
{
    public static class SErrorManager
    {
        static SErrorManager()
        {
            InitClass();
        }

        private static void InitClass()
        {
            SErrorManager._DebugOn = true;
            SErrorManager._ErrorDict = new Dictionary<string, TErrorBase>()
            {
                //{"ParameterCountMismatch", new TError("CommandText is {0}\nParameter count is {1}\nBut ParameterNames lenght is {2}", _DebugOn)},
                {"ExecuteNonQueryException", new TError("ExecuteNonQuery() threw an exception. CommandText is \"{0}\"\nQueryType is \"{1}\"", _DebugOn)},
                {"TDataBaseInfoConstructionIncomplete", new TError("Construction of TDatabaseInfo object is incomplete. _ConstructionLevel must be {0}; but it is {1}", _DebugOn)},
                {"EntityIDIndexNotFount", new TError("Entity.ID not named as \"{0}\" You must use this name for id property of Entity.", _DebugOn)},
                {"DuplicateKeyFound", new TError("Key with name <{0}> already exists. Count of duplicate existence is {1}.", _DebugOn)},
                {"CountMismatch", new TError("Count Mismatch: {0} is {2}; but {1} is {3}", _DebugOn)},
                {"ValuesMismatch", new TError("Values Mismatch!Value of {0} is {2} and {1} is {3}. {0}!={1}", _DebugOn)},
                {"BooleanFlagWrong", new TError("Boolean Flag {0} is set to {1} but it must be {2}", _DebugOn)},
                {"InvalidErrorCount", new TError("Error count is {0}. Please review your code", _DebugOn)},
                {"InvalidValue", new TError("Value {0} must be {1} but it is {2}", _DebugOn)},
                {"InvalidComparison", new TError("{0} is not true.", _DebugOn)},
                {"ScalarComparisonFalse", new TError("{0} is not true. {1}-{2}", _DebugOn)},
                {"GenericException", new TError("Exception Thrown!", _DebugOn)},
                {"ValueCanNotBeNull", new TError("{0} is not initialized", _DebugOn)},
                {"ExceptionThrown", new TError("Custom Error Encountered.", _DebugOn)},
                {"CheckFailed", new TError("Check for {0} failed", _DebugOn)},
                {"EqualityCheckFailed", new TError("Check for {0} failed. {1} != {2}", _DebugOn)},
                {"ShouldBeSingle", new TError("{0} should be single but it repeated {1} times.", _DebugOn)},
                {"EnumNotSet", new TError("Enum struct {0} has invalid value of {1}", _DebugOn)},
                {"KeyNotFound", new TError("Key not found : {0}.", _DebugOn)},
                {"IndexOutOfRange", new TError("Index out of range: i={0} limit={1}", _DebugOn)},
                {"CommandExecutionFailed", new TError("Command Execution Failed. Command Text : {0}.", _DebugOn)},
            };
        }
        private static Dictionary<string, TErrorBase> _ErrorDict;
        private static bool _DebugOn;
        public static bool DebugOn
        {
            get { return SErrorManager._DebugOn; }
            //set { SErrorManager._DebugOn = value; }
        }

        public static TErrorBase Errors(string key)
        {
            if (_ErrorDict.ContainsKey(key))
                return _ErrorDict[key];
            else
                throw new KeyNotFoundException();
        }
        public static TCustomError CustomError()
        {
            return new TCustomError(_DebugOn);
        }

        public static TException Exception()
        {
            return new TException(_DebugOn);
        }
        //private static void Set(AError value)
        //{
        //    if (!_Errors.ContainsKey(key))
        //        _Errors.Add(key, value);
        //    else
        //        _Errors[key] = value;
        //}
    }
}
